﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Controls;

namespace Jbe.TestSuite.RtfEditor.Presentation
{
    public class BindableRichTextBox : RichTextBox
    {
        public static readonly DependencyProperty DocumentProperty = DependencyProperty.Register("Document", typeof(FlowDocument), 
            typeof(BindableRichTextBox), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(DocumentChangedHandler)));


        public new FlowDocument Document
        {
            get { return (FlowDocument)GetValue(DocumentProperty); }
            set { SetValue(DocumentProperty, value); }
        }


        private static void DocumentChangedHandler(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            RichTextBox richTextBox = (RichTextBox)source;
            richTextBox.Document = (FlowDocument)e.NewValue;
        }
    }
}
